#define _CRT_SECURE_NO_WARNINGS 1

#include "StackList.h"

void StackPush(Node** ppHead, int x) {
	Node* node = (Node*)malloc(sizeof(Node));

	node->data = x;
	node->next = *ppHead;
	*ppHead = node;
}
void StackPop(Node** ppHead) {
	assert(*ppHead);
	
	Node* tmp = *ppHead;

	*ppHead = (*ppHead)->next;

	free(tmp);
}
int StackTop(Node* pHead) {
	assert(pHead);

	return pHead->data;
}
void StackPrint(Node* pHead) {
	assert(pHead);
	Node* cur = pHead;
	
	while (cur) {
		printf("%d->", cur->data);
		cur = cur->next;
	}
	printf("NULL\n");
}

int StackisEmpty(Node* pHead) {
	if (pHead) {
		return 1;
	}
	else {
		return 0;
	}
}

void StackDestroy(Node** ppHead) {
	assert(*ppHead);
	Node* cur = *ppHead;

	while (cur) {
		Node* next = cur->next;
		free(cur);
		cur = next;
	}
	*ppHead = NULL;
}
